home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / jazlib.arc / JZFIND.DMO < prev    next >
Text File  |  1988-12-18  |  2KB  |  74 lines

  1. /*
  2. ┌────────────────────────────────────────────────────────────────────────────┐
  3. │ Title   : JZFIND                                 │
  4. │ Purpose : Search through the entire disk, including all subdirectories     │
  5. │        for a file specified by the user.                     │
  6. │                                         │
  7. │               Usage:     JZFIND <Filename>                 │
  8. │                                         │
  9. │    Written by Jack Zucker - 75766,1336    301-794-5950  on  1/28/86     │
  10. └────────────────────────────────────────────────────────────────────────────┘
  11. */
  12.  
  13. #include <jzdirect.h>
  14.  
  15. char startdir[100];
  16. char filename[100];
  17. int FOUND = 0;
  18.  
  19. main(argc,argv)
  20. int argc;
  21. char **argv;
  22. {
  23.  
  24.   printf("\nJZFIND (C) JazSoft by Jack A. Zucker (301) 794-5950 | 75766,1336");
  25.  
  26.   if (argc != 2) {
  27.     printf("\nUsage:    JZFIND <Filename>\n");
  28.     exit(1);
  29.   }
  30.  
  31.   strcpy(filename,strupr(*++argv)); /* get filename in global variable */
  32.   strcpy(startdir,"");                /* start out with the root direct  */
  33.  
  34.   searchdir(startdir);              /* start recursin'                 */
  35.  
  36.   if ( ! FOUND ) printf("\n\nNo files were found matching %s",filename);
  37.  
  38. }
  39.  
  40. searchdir(fspec)
  41. char *fspec;
  42. #define SUBDIR 0x10        /* attribute for sub directory */
  43. #define NORMAL 0x20        /* attribute for normal direct */
  44. {
  45.   int werr;
  46.   TDIR wdir;            /* hold the dos error number   */
  47.   int w;            /* work variable           */
  48.   char path[100],temp[100];    /* work STRING variables       */
  49.  
  50.   strcpy(path,fspec);        /* copy new file spec to work string */
  51.   strcat(path,"\\*.*");         /* put /*.* after it                 */
  52.  
  53.   /* get subdirs and normal files */
  54.   werr = jzfndfst(path,NORMAL | SUBDIR,&wdir);
  55.  
  56.   if (! werr )            /* we found at least one match */
  57.     do {
  58.       if (wdir.attr == SUBDIR && wdir.name[0] != '.') {
  59.     strcpy(path,fspec);
  60.     strcat(path,"\\");
  61.     strcat(path,wdir.name);   /* append the new subdir         */
  62.     searchdir(path);      /* recurse against the new file spec */
  63.       }
  64.  
  65.       if (jzwldcrd(wdir.name,filename)) {    /* file matches user specs */
  66.     FOUND = 1;                 /* we found at least one match */
  67.     strcpy(temp,fspec);             /* parse out the path    */
  68.     printf("\n%s found in %s",wdir.name,*temp ? temp : "\\");
  69.       }
  70.  
  71.       werr = jzfndnxt(&wdir);              /* get the next directory item */
  72.     } while (! werr);                  /* loop until no more files    */
  73. }
  74.